<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_detail.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>

    <script src="js/common.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- spacer 不实现任何内容 只是占位 把后面a标签撑到右侧去 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_lists.html">博客列表</a>
        <a href="blog_edit.html">写博客</a>
        <a href="javascript:logout()">注销</a>
    </div>


    <div class="container">
        <!-- 左侧用户信息 -->
        <div class="container-left">
            <!-- 用这个元素表示用户信息 -->
            <div class="card">
                <!-- 头像 -->
                <img src="img/tx.jpg" alt="">
                <!-- 姓名 -->
                <h3 id="username"></h3>
                <a href="#">github地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span id="artCount"></span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容区域 -->
        <div class="container-right">
            <div class="blog-detail">
                <h3 id="title"></h3>
                <div class="date">
                    发布时间:<span id="updatetime"></span>&nbsp;&nbsp;&nbsp;&nbsp;阅读量:<span id="rcount">1</span>
                </div>
                <p id="editorDiv"></p>
            </div>
        </div>
    </div>

    <script>

        var editormd;
        function initEdit(md) {
            editormd = editormd.markdownToHTML("editorDiv", {
                markdown: md,
            });
        }

        //查询文章详情
        function getArtDetail(id) {
            if (id == "") {
                alert("非法参数");
                return;
            }
            jQuery.ajax({
                url: "art/detail",
                type: "post",
                data: { "id": id },
                success: function (result) {
                    if (result != null && result.code == 200) {
                        jQuery("#title").html(result.data.title);
                        jQuery("#updatetime").html(result.data.updatetime);
                        jQuery("#rcount").html(result.data.rcount);
                        initEdit(result.data.content);
                        //得到用户id
                        showUser(result.data.uid);
                    } else {
                        alert("查询失败，请重试");
                    }
                }
            });
        }

        getArtDetail(getUrlValue("id"));


        //查询用户的详情信息
        function showUser(id) {
            jQuery.ajax({
                url: "/user/getuserbyid",
                type: "post",
                data: { "id": id },
                success: function (result) {
                    if (result != null && result.code == 200 && result.data.id > 0) {
                        jQuery("#username").text(result.data.username);
                        jQuery("#artCount").text(result.data.artCount);
                    } else {
                        alert("抱歉查询用户信息失败，请重试");
                    }
                }
            });
        }
        //阅读量+1
        function updataRCount() {
            var id = getUrlValue("id");
            if (id != "") {
                jQuery.ajax({
                    url: "/art/incr-rcount",
                    type: "post",
                    data: { "id": id },
                    //不关注是否成功
                    success: function (result) { }
                });
            }

        }
        updataRCount();

    </script>

</body>

</html>